package com.loto.webapp.bo.impl.manage;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.loto.webapp.bo.manage.FeeFlowBo;
import com.loto.webapp.dao.manage.FeeFlowDao;
import com.loto.webapp.model.Dict.FeeFlowType;
import com.loto.webapp.model.FeeFlow;
import com.loto.webapp.model.Dict.RefType;
import com.loto.webapp.model.Dict.SettlementType;

public class FeeFlowBoImpl implements FeeFlowBo {
	FeeFlowDao feeFlowDao;

	public void setFeeFlowDao(FeeFlowDao feeFlowDao) {
		this.feeFlowDao = feeFlowDao;
	}

	public List<FeeFlow> countFeeGroupByTypeByDate(Date beginDate, Date endDate) {
		return feeFlowDao.countFeeGroupByTypeByDate(beginDate, endDate);
	}

	public List<FeeFlow> countFeeGroupByTypeByDateAndRef(Date beginDate,
			Date endDate, RefType refType) {
		return feeFlowDao.countFeeGroupByTypeByDateAndRef(beginDate, endDate,
				refType);
	}

	public List<FeeFlow> getDetail(Date beginDate, Date endDate,
			int settlementType) {
		List<FeeFlow> feeFlowList = null;
		if (settlementType == SettlementType.ALLRECHARGE.getIndex())
			return getTotalSupplementDetail(beginDate, endDate);
		if (settlementType == SettlementType.ORDERPAY.getIndex())
			return getOrderPayOutDetail(beginDate, endDate);
		if (settlementType == SettlementType.PACKPAY.getIndex())
			return getPackPayOutDetail(beginDate, endDate);
		if (settlementType == SettlementType.ALLREFUND.getIndex())
			return getTotalRefundDetail(beginDate, endDate);
		if (settlementType == SettlementType.GOODSREFUND.getIndex())
			return getGoodsRefundDetail(beginDate, endDate);
		if (settlementType == SettlementType.PACKREFUND.getIndex())
			return getPackRefundDetail(beginDate, endDate);
		if (settlementType == SettlementType.OTHERREFUND.getIndex())
			return getOtherRefundDetail(beginDate, endDate);
		if (settlementType == SettlementType.ALLCREDIT.getIndex())
			return getTotalDeductDetail(beginDate, endDate);
		if (settlementType == SettlementType.GOODSCREDIT.getIndex())
			return getGoodsDeductDetail(beginDate, endDate);
		if (settlementType == SettlementType.PACKCREDIT.getIndex())
			return getPackDeductDetail(beginDate, endDate);
		if (settlementType == SettlementType.OTHERCREDIT.getIndex())
			return getOtherDeductDetail(beginDate, endDate);
		if (settlementType == SettlementType.BANKREFUND.getIndex())
			return getBankDeductDetail(beginDate, endDate);
		return feeFlowList;
	}

	//BANKREFUND
	public List<FeeFlow> getBankDeductDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.ALIPAYREFUND);
		feeFlowTypeList.add(FeeFlowType.CHINAPAYCNREFUND);
		feeFlowTypeList.add(FeeFlowType.CHINAPAYREFUND);
		feeFlowTypeList.add(FeeFlowType.ALIPAYFORCARDREFUND);
		feeFlowTypeList.add(FeeFlowType.IPSREFUND);
		feeFlowTypeList.add(FeeFlowType.PAYPALREFUND);
		feeFlowTypeList.add(FeeFlowType.REMITREFUND);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

	//GOODSCREDIT
	public List<FeeFlow> getGoodsDeductDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.CREDIT);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.GOODS);
	}

	//GOODSREFUND
	public List<FeeFlow> getGoodsRefundDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.REFUND);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.GOODS);
	}

	//ORDERPAY
	public List<FeeFlow> getOrderPayOutDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.ORDERPAY);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

	//OTHERCREDIT
	public List<FeeFlow> getOtherDeductDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.CREDIT);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.OTHERS);
	}

	//OTHERREFUND
	public List<FeeFlow> getOtherRefundDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.REFUND);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.OTHERS);
	}

	//PACKCREDIT
	public List<FeeFlow> getPackDeductDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.CREDIT);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.PACK);
	}

	//PACKPAY
	public List<FeeFlow> getPackPayOutDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.PACKPAY);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

	//PACKREFUND
	public List<FeeFlow> getPackRefundDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.REFUND);
		return feeFlowDao.getFeeFlowDetailByDateAndRef(beginDate, endDate,
				feeFlowTypeList,RefType.PACK);
	}

	//ALLCREDIT
	public List<FeeFlow> getTotalDeductDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.CREDIT);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

	//ALLREFUND
	public List<FeeFlow> getTotalRefundDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.REFUND);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

	//ALLRECHARGE
	public List<FeeFlow> getTotalSupplementDetail(Date beginDate, Date endDate) {
		List<FeeFlowType> feeFlowTypeList = new ArrayList<FeeFlowType>();
		feeFlowTypeList.add(FeeFlowType.PAYPALRECHARGE);
		feeFlowTypeList.add(FeeFlowType.IPSRECHARGE);
		feeFlowTypeList.add(FeeFlowType.REMITRECHARGE);
		feeFlowTypeList.add(FeeFlowType.ALIRECHARGE);
		feeFlowTypeList.add(FeeFlowType.CHINAPAYRECHARGE);
		feeFlowTypeList.add(FeeFlowType.CHINAPAYCNRECHARGE);
		feeFlowTypeList.add(FeeFlowType.ALIPAYFORCARDRECHARGE);
		return feeFlowDao.getFeeFlowDetailByDate(beginDate, endDate,
				feeFlowTypeList);
	}

}
